<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
    ></avue-crud>
  </basic-container>
</template>

<script>
import { getFeeDetailList } from "@/api/meter/checkCost";
import { mapGetters } from "vuex";
export default {
  name: "costDetail",
  data() {
    return {
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      option: {
        menu: false,
        height: "auto",
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: "序号",
        viewBtn: false,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        selection: false,
        dialogClickModal: false,
        column: [
          {
            label: "时间",
            prop: "dayCost",
          },
          {
            label: "日电费",
            prop: "dayCost",
          },
          {
            label: "平电费",
            prop: "flatCost",
          },
          {
            label: "日使用电量",
            prop: "kmDayUsage",
          },
          {
            label: "谷电费",
            prop: "lowCost",
          },
          {
            label: "计量日",
            prop: "meterDay",
          },
          {
            label: "计量月",
            prop: "meterMonth",
          },
          {
            label: "尖峰电费",
            prop: "sharpCost",
          },
        ],
      },
      data: [],
    };
  },
  mounted() {
    if (this.$route.query.id) {
      this.onLoad(this.page, { roomId: this.$route.query.id });
    }
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.contract_add, false),
        viewBtn: this.vaildData(this.permission.contract_view, false),
        delBtn: this.vaildData(this.permission.contract_delete, false),
        editBtn: this.vaildData(this.permission.contract_edit, false),
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
  },
  methods: {
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },

    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },

    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },

    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },

    refreshChange() {
      this.onLoad(this.page, this.query);
    },

    onLoad(page, params = {}) {
      this.loading = true;
      getFeeDetailList(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
